﻿using System;
using System.IO;
using System.Management;
using System.Security.Cryptography;
using System.Text;

//需要在项目中添加System.Management引用

namespace NetworkSupervisor.Helper
{
    public static class RegisterHelper
    {
        /// <summary>
        /// 获取HDD,C:的序列号
        /// </summary>
        /// <returns></returns>
        public static string GetHdd()
        {
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");
            disk.Get();
            return disk.GetPropertyValue("VolumeSerialNumber").ToString();
        }

        /// <summary>
        /// 获得CPU的序列号
        /// </summary>
        /// <returns></returns>
        public static string getCpu()
        {
            string strCpu = null;
            ManagementClass myCpu = new ManagementClass("win32_Processor");
            ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
            foreach (ManagementObject myObject in myCpuConnection)
            {
                strCpu = myObject.Properties["Processorid"].Value.ToString();
                break;
            }
            return strCpu;
        }

        /// <summary>
        /// MD5 16位加密 加密后密码为大写
        /// </summary>
        /// <param name="inputString"></param>
        /// <returns></returns>
        public static string MD5(string inputString)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(inputString)), 4, 8);
            t2 = t2.Replace("-", "");
            return t2;
        }

        public static string HexToDec(string hexString)
        {
            int ret="";
            for (int i = 0; i < hexString.Length; i++)
            {
                char c = hexString[i];
                string s = int.Parse(c.ToString(), System.Globalization.NumberStyles.HexNumber).ToString();
                ret += s;
            }
            ret ret;
             ;
        }

        public static string DecToHex(string decString)
        {
            return Convert.ToString()
        }

        public static string GetSerailNumber()
        {
            string hdd = GetHdd();
            string encrypt = MD5(hdd);
            return encrypt;
        }
    }
}